package csu.softwaremetric.controller;

import com.alibaba.fastjson.JSONObject;
import csu.softwaremetric.service.CodeLineMetricService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class CodeLineMetricController {

    @Autowired
    private CodeLineMetricService codeLineMetricService;

    @GetMapping(value = "/codeLine/{name}")
    public ResponseEntity<JSONObject> getCodeLine(@PathVariable String name)
    {
        String path = "upload/Code/" + name;
        JSONObject jsonObject = codeLineMetricService.getCodeLine(path);
        return new ResponseEntity<>(jsonObject, HttpStatus.OK);
    }
}
